import MToast from './MToast.vue';

export default function install(Vue) {
    Vue.component('MToast', MToast);

    Vue.prototype.mirror.toast = function(content, time, color, badge) {
        var obj = this.instance.get("core_toast");
        if (color != "main" && color != "sub" && color != "danger") {
            color = null;
        }
        var msg = { content };
        color && (msg.color = color);
        badge && (msg.badge = badge);
        obj.list.push(msg);
        setTimeout((function() {
            return function() {
                for (var i = 0; i < obj.list.length; i++) {
                    if (obj.list[i].content == content) {
                        obj.list.splice(i, 1);
                        break;
                    }
                }
            }
        }(content)), !!time ? time : 1500 + content.length * 70);
    }
}